package org.dromara.system.service.impl;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import me.chanjar.weixin.common.error.WxErrorException;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.system.service.WechatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class WechatServiceImpl implements WechatService {


    @Autowired
    private WxMaService wxMaService;

    public static final String appId = SpringUtils.getProperty("justauth.type.wechat.client-id");
    public static final String appSecret = SpringUtils.getProperty("justauth.type.wechat.client-secret");
    private final String WECHAT_LOGIN_URL = "https://api.weixin.qq.com/sns/jscode2session";


    @Override
    public String loginWithWeChat(String code) {
        try {
            WxMaJscode2SessionResult sessionInfo = wxMaService.getUserService().getSessionInfo(code);
            System.out.println(sessionInfo.getOpenid());
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
        return "";
    }
}
